#!/bin/bash

FILES=""
DIR=""

usage() {
	echo "Usage: summ_code.sh <directory | file>"
	exit 1
}



if [ $# -lt 1 ]; then
	usage
fi

DIR=$1

if [ -d $DIR ]; then
	FILES=$(find $DIR -regextype egrep -regex '.*.(py|c|h|sh)')
else 
	FILES=$1

fi

for f in $FILES
do
	TYPE=${f##*.}
	if [ "X"$TYPE == "Xc" -o "X"$TYPE == "Xh" ]; then
		echo "$(basename $f):"
		sed -r -f c.sed "$f"
		#echo "c type"

	elif [ "X"$TYPE == "Xpy" ]; then
		echo "$(basename $f):"
		sed -r -f python.sed  "$f" | \
		sed -r -e 's/(\s{1,}|[^"'\'']|^)#.*$/\1/' \
		     -e   '/^\s*$/d'
		#echo "python type "
       	elif [ "X"$TYPE == "Xsh" ]; then 
		echo "$(basename $f):"
		sed -r -e '/^\s*$/d' \
			-e '/^\s*#[^!].*$/d'  "$f"
		#echo "shell type"
	fi

done

	

